package com.yssystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yssystem.domain.Do.SysMenuDO;
import com.yssystem.domain.SysMenu;
import com.yssystem.service.SysMenuService;
import com.yssystem.mapper.SysMenuMapper;
import com.yssystem.utils.TreeMenuUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
* @author 28783
* @description 针对表【sys_menu(菜单表)】的数据库操作Service实现
* @createDate 2024-07-11 15:14:55
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
    implements SysMenuService {
        //数据渲染

    @Override
    public List<SysMenuDO> getlist(Wrapper<SysMenu> queryWrapper) {
        List<SysMenu> list = list(queryWrapper);
        List<SysMenuDO> list1 = new ArrayList<>();
        for ( SysMenu e :list) {
//            System.out.println(e);
            SysMenuDO sysMenuDO = new SysMenuDO();
            BeanUtils.copyProperties(e,sysMenuDO);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 将日期对象转换为指定格式的字符串
            String formattedDate = sdf.format(sysMenuDO.getCreateTime());
            sysMenuDO.setTime(formattedDate);
            list1.add(sysMenuDO);
        }
//        System.out.println(list1);
        List<SysMenuDO> list2 = TreeMenuUtil.createTree(list1, 0);
        return list2;
    }
}




